package com.example.filesystem.repository;

import com.example.filesystem.model.UploadChunk;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface UploadChunkRepository extends JpaRepository<UploadChunk, Long> {
    // 统计已上传的分片数量
    int countByUploadId(String uploadId);

    @Query("select uc from UploadChunk uc  WHERE uc.uploadId = :uploadId and  uc.chunkNumber = :chunkNumber")
    UploadChunk checkChunk(String uploadId, Integer chunkNumber);

    @Modifying(clearAutomatically = true)
    @Query("delete   from UploadChunk   WHERE uploadId = :uploadId")
    void deleteChunk(String uploadId);
}